# Copyright 2025 Memgraph Ltd.
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
# License, and you may not use this file except in compliance with the Business Source License.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0, included in the file
# licenses/APL.txt.

import sys

import pytest
from common import memgraph


def test_all_show_metrics_info_values_are_present(memgraph):
    expected_metrics = [
        {"name": "AverageDegree", "type": "General", "metric type": "Gauge"},
        {"name": "EdgeCount", "type": "General", "metric type": "Gauge"},
        {"name": "VertexCount", "type": "General", "metric type": "Gauge"},
        {"name": "SocketConnect_us_50p", "type": "General", "metric type": "Histogram"},
        {"name": "SocketConnect_us_90p", "type": "General", "metric type": "Histogram"},
        {"name": "SocketConnect_us_99p", "type": "General", "metric type": "Histogram"},
        {"name": "BecomeLeaderSuccess", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "DemoteInstance", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "DemoteMainToReplicaRpcFail", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "DemoteMainToReplicaRpcSuccess", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "EnableWritingOnMainRpcFail", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "EnableWritingOnMainRpcSuccess", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "FailedToBecomeLeader", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "GetDatabaseHistoriesRpcFail", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "GetDatabaseHistoriesRpcSuccess", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "NoAliveInstanceFailedFailovers", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "PromoteToMainRpcFail", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "PromoteToMainRpcSuccess", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "RaftFailedFailovers", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "RegisterReplicaOnMainRpcFail", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "RegisterReplicaOnMainRpcSuccess", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "RemoveCoordInstance", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "ReplicaRecoveryFail", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "ReplicaRecoverySkip", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "ReplicaRecoverySuccess", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "ShowInstance", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "ShowInstances", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "StateCheckRpcFail", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "StateCheckRpcSuccess", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "SuccessfulFailovers", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "SwapMainUUIDRpcFail", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "SwapMainUUIDRpcSuccess", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "UnregisterReplInstance", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "UnregisterReplicaRpcFail", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "UnregisterReplicaRpcSuccess", "type": "HighAvailability", "metric type": "Counter"},
        {"name": "ChooseMostUpToDateInstance_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "ChooseMostUpToDateInstance_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "ChooseMostUpToDateInstance_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "CurrentWalRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "CurrentWalRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "CurrentWalRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "DataFailover_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "DataFailover_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "DataFailover_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "DemoteMainToReplicaRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "DemoteMainToReplicaRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "DemoteMainToReplicaRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "EnableWritingOnMainRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "EnableWritingOnMainRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "EnableWritingOnMainRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "FinalizeTxnReplication_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "FinalizeTxnReplication_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "FinalizeTxnReplication_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "FrequentHeartbeatRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "FrequentHeartbeatRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "FrequentHeartbeatRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "GetDatabaseHistoriesRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "GetDatabaseHistoriesRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "GetDatabaseHistoriesRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "GetHistories_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "GetHistories_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "GetHistories_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "HeartbeatRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "HeartbeatRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "HeartbeatRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "InstanceFailCallback_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "InstanceFailCallback_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "InstanceFailCallback_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "InstanceSuccCallback_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "InstanceSuccCallback_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "InstanceSuccCallback_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "PrepareCommitRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "PrepareCommitRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "PrepareCommitRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "PromoteToMainRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "PromoteToMainRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "PromoteToMainRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "RegisterReplicaOnMainRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "RegisterReplicaOnMainRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "RegisterReplicaOnMainRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "ReplicaStream_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "ReplicaStream_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "ReplicaStream_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "SnapshotRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "SnapshotRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "SnapshotRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "StartTxnReplication_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "StartTxnReplication_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "StartTxnReplication_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "StateCheckRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "StateCheckRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "StateCheckRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "SystemRecoveryRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "SystemRecoveryRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "SystemRecoveryRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "UnregisterReplicaRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "UnregisterReplicaRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "UnregisterReplicaRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "WalFilesRpc_us_50p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "WalFilesRpc_us_90p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "WalFilesRpc_us_99p", "type": "HighAvailability", "metric type": "Histogram"},
        {"name": "ActiveEdgePropertyIndices", "type": "Index", "metric type": "Counter"},
        {"name": "ActiveEdgeTypeIndices", "type": "Index", "metric type": "Counter"},
        {"name": "ActiveEdgeTypePropertyIndices", "type": "Index", "metric type": "Counter"},
        {"name": "ActiveLabelIndices", "type": "Index", "metric type": "Counter"},
        {"name": "ActiveLabelPropertyIndices", "type": "Index", "metric type": "Counter"},
        {"name": "ActivePointIndices", "type": "Index", "metric type": "Counter"},
        {"name": "ActiveTextEdgeIndices", "type": "Index", "metric type": "Counter"},
        {"name": "ActiveTextIndices", "type": "Index", "metric type": "Counter"},
        {"name": "ActiveVectorEdgeIndices", "type": "Index", "metric type": "Counter"},
        {"name": "ActiveVectorIndices", "type": "Index", "metric type": "Counter"},
        {"name": "UnreleasedDeltaObjects", "type": "Memory", "metric type": "Counter"},
        {"name": "DiskUsage", "type": "Memory", "metric type": "Gauge"},
        {"name": "MemoryRes", "type": "Memory", "metric type": "Gauge"},
        {"name": "PeakMemoryRes", "type": "Memory", "metric type": "Gauge"},
        {"name": "GCLatency_us_50p", "type": "Memory", "metric type": "Histogram"},
        {"name": "GCLatency_us_90p", "type": "Memory", "metric type": "Histogram"},
        {"name": "GCLatency_us_99p", "type": "Memory", "metric type": "Histogram"},
        {"name": "GCSkiplistCleanupLatency_us_50p", "type": "Memory", "metric type": "Histogram"},
        {"name": "GCSkiplistCleanupLatency_us_90p", "type": "Memory", "metric type": "Histogram"},
        {"name": "GCSkiplistCleanupLatency_us_99p", "type": "Memory", "metric type": "Histogram"},
        {"name": "AccumulateOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "AggregateOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ApplyOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "CallProcedureOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "CartesianOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ConstructNamedPathOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "CreateExpandOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "CreateNodeOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "DeleteOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "DistinctOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "EdgeUniquenessFilterOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "EmptyResultOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "EvaluatePatternFilterOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ExpandOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ExpandVariableOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "FilterOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ForeachOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "HashJoinOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "IndexedJoinOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "LimitOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "MergeOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "OnceOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "OptionalOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "OrderByOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "PeriodicCommitOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "PeriodicSubqueryOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ProduceOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "RemoveLabelsOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "RemoveNestedPropertyOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "RemovePropertyOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "RollUpApplyOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByEdgeIdOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByEdgeOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByEdgePropertyOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByEdgePropertyRangeOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByEdgePropertyValueOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByEdgeTypeOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByEdgeTypePropertyOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByEdgeTypePropertyRangeOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByEdgeTypePropertyValueOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByIdOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByLabelOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByLabelPropertiesOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByPointDistanceOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllByPointWithinbboxOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "ScanAllOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "SetLabelsOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "SetNestedPropertyOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "SetPropertiesOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "SetPropertyOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "SkipOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "UnionOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "UnwindOperator", "type": "Operator", "metric type": "Counter"},
        {"name": "QueryExecutionLatency_us_50p", "type": "Query", "metric type": "Histogram"},
        {"name": "QueryExecutionLatency_us_90p", "type": "Query", "metric type": "Histogram"},
        {"name": "QueryExecutionLatency_us_99p", "type": "Query", "metric type": "Histogram"},
        {"name": "ReadQuery", "type": "QueryType", "metric type": "Counter"},
        {"name": "ReadWriteQuery", "type": "QueryType", "metric type": "Counter"},
        {"name": "WriteQuery", "type": "QueryType", "metric type": "Counter"},
        {"name": "ShowSchema", "type": "SchemaInfo", "metric type": "Counter"},
        {"name": "ActiveBoltSessions", "type": "Session", "metric type": "Counter"},
        {"name": "ActiveSSLSessions", "type": "Session", "metric type": "Counter"},
        {"name": "ActiveSessions", "type": "Session", "metric type": "Counter"},
        {"name": "ActiveTCPSessions", "type": "Session", "metric type": "Counter"},
        {"name": "ActiveWebSocketSessions", "type": "Session", "metric type": "Counter"},
        {"name": "BoltMessages", "type": "Session", "metric type": "Counter"},
        {"name": "SnapshotCreationLatency_us_50p", "type": "Snapshot", "metric type": "Histogram"},
        {"name": "SnapshotCreationLatency_us_90p", "type": "Snapshot", "metric type": "Histogram"},
        {"name": "SnapshotCreationLatency_us_99p", "type": "Snapshot", "metric type": "Histogram"},
        {"name": "SnapshotRecoveryLatency_us_50p", "type": "Snapshot", "metric type": "Histogram"},
        {"name": "SnapshotRecoveryLatency_us_90p", "type": "Snapshot", "metric type": "Histogram"},
        {"name": "SnapshotRecoveryLatency_us_99p", "type": "Snapshot", "metric type": "Histogram"},
        {"name": "MessagesConsumed", "type": "Stream", "metric type": "Counter"},
        {"name": "StreamsCreated", "type": "Stream", "metric type": "Counter"},
        {"name": "DeletedEdges", "type": "TTL", "metric type": "Counter"},
        {"name": "DeletedNodes", "type": "TTL", "metric type": "Counter"},
        {"name": "ActiveTransactions", "type": "Transaction", "metric type": "Counter"},
        {"name": "CommitedTransactions", "type": "Transaction", "metric type": "Counter"},
        {"name": "FailedPrepare", "type": "Transaction", "metric type": "Counter"},
        {"name": "FailedPull", "type": "Transaction", "metric type": "Counter"},
        {"name": "FailedQuery", "type": "Transaction", "metric type": "Counter"},
        {"name": "RollbackedTransactions", "type": "Transaction", "metric type": "Counter"},
        {"name": "SuccessfulQuery", "type": "Transaction", "metric type": "Counter"},
        {"name": "TransientErrors", "type": "Transaction", "metric type": "Counter"},
        {"name": "WriteWriteConflicts", "type": "Transaction", "metric type": "Counter"},
        {"name": "TriggersCreated", "type": "Trigger", "metric type": "Counter"},
        {"name": "TriggersExecuted", "type": "Trigger", "metric type": "Counter"},
    ]
    results = list(memgraph.execute_and_fetch("SHOW METRICS INFO"))
    actual_metrics = [{"name": x["name"], "type": x["type"], "metric type": x["metric type"]} for x in results]

    for expected, actual in zip(expected_metrics, actual_metrics):
        assert expected == actual


if __name__ == "__main__":
    sys.exit(pytest.main([__file__, "-rA"]))
